<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

    <script>
        //  const it = [1, 2, 3];
        //  for (const item of it) {
        //      console.log(item); // 1  2  3
        //  }

        const it = [1, 2, 3, 45];
        for (const item of it) {
            console.log(item);
        }

        //在for of 中取得数组的索引值
        const arr1 = [1, 2, 3]
            //keys()得到的是索引的可遍历对象 可以遍历出索引值
        for (const key of arr1.keys()) {
            console.log(key); //0  1  2
        }

        //values()得到的是指的可遍历对象  可以遍历出值
        for (const value of arr1.values()) {
            console.log(value); //1 2 3
        }

        //entries()得到的是索引+值组成的数组的可遍历对象

        for (const entries of arr1.entries()) {
            console.log(entries); // [0, 1] [1, 2] [2,3]
        }

        //或者
        for (const [index, value] of arr1.entries()) {
            console.log(index, value); //0 1  1 2  2 3
        }
    </script>
</body>

</html>